package io.zhoujie.modules.app.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.JsonObject;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import io.zhoujie.common.utils.R;
import io.zhoujie.modules.app.entity.AppReplyEntity;
import io.zhoujie.modules.app.service.AppReplyService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 管理端——问答管理
 *
 * @author zhoujie
 * @email 813685764@qq.com
 * @date 2024-02-20 12:10:43
 */
@RestController
@Api(tags = "手机端——问答管理")
@RequestMapping("app/reply")
@Transactional(rollbackFor = Exception.class )
public class AppReplyController {
    @Resource
    private AppReplyService appReplyService;

    /**
     * 查询问题表
     * @param appReplyEntity
     * @return
     */
    @GetMapping("/list")
    public R list(AppReplyEntity appReplyEntity) {
        List<AppReplyEntity> list = appReplyService.selectReplyList(appReplyEntity);
        return R.ok().put("page", list);
    }

    /**
     * 增加问题
     * @param appReplyEntity
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody AppReplyEntity appReplyEntity) {
        appReplyService.insertReply(appReplyEntity);
        return R.ok();
    }

    /**
     * 问题描述
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public R detail(@RequestParam("id") Integer id) {
        AppReplyEntity detail = appReplyService.selectReplyByID(id);
        return R.ok().put("detail", detail);
    }

    /**
     * 添加回复
     * @param list
     * @return
     */
    @PostMapping("/addComment")
    public R addComment(@RequestBody Map<String,Object> list) {
        int cod = appReplyService.insertReplys(list);
        return R.ok();
    }

    /**
     * 问题回复表
     * @param postId
     * @return
     */
    @GetMapping("listreply")
    public R listReply(@RequestParam("postId") Integer postId) {
        List<JSONObject> list = appReplyService.listReply(postId);
        return R.ok().put("data",list);
    }

    /**
     * 设置最优解
     * @param list
     * @return
     */
    @PostMapping("/setTop")
    public R setTop(@RequestBody Map<String,Object> list) {
        int cod = appReplyService.setTop(list);
        return R.ok();
    }
    @PostMapping("/delete")
    public R delete(@RequestBody Map<String,Object> id) {
        int cod = appReplyService.getBaseMapper().deleteById((Serializable) id.get("id"));
        return R.ok();
    }
}
